package com.frostmourne.mxsguimaker.objects;

import com.gitee.mxstarsex.MXStarsEx;
import com.gitee.mxstarsex.objects.TimeObject;
import com.gitee.mxstarsex.objects.builders.bukkit.item.ItemBuilderNeo;
import com.gitee.mxstarsex.objects.builders.bukkit.message.MessageBuilder;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import java.util.Date;

public class JSUtils {

    public ItemBuilderNeo toItemBuilder(ItemStack itemStack){
        return new ItemBuilderNeo(itemStack);
    }

    public ItemStack deserializeToItemStack(String data){
        return ItemBuilderNeo.deserializeToItemStack(data);
    }
    public String serializeToItemStack(ItemStack item){
        return ItemBuilderNeo.serialize(item);
    }

    public MessageBuilder toMessageBuilder(CommandSender sender){
        return MessageBuilder.getMessageBuilder(sender);
    }

    public void setCD(Player player,String source,long seconds){
        MXStarsEx.getCdManager().setPlayerCd(player,source,new TimeObject(new Date().getTime(),seconds));
    }
    public boolean isCD(Player player,String source){
        TimeObject playerTimeObject = MXStarsEx.getCdManager().getPlayerTimeObject(player, source);
        if (playerTimeObject != null){
            return playerTimeObject.isTimer();
        }
        return true;
    }

}
